﻿using System.Collections;
using System.Configuration.Install;
using System.ServiceProcess;
using System.ComponentModel;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using System;



namespace FileMonitor.Service
{
    [RunInstaller(true)]
    public partial class MonitorServiceInstaller : Installer
    {
        private const string s_serviceName = "FileMonitorService";
        private const string s_serviceDesc = "FileMonitorService";

        private ServiceInstaller serviceInstaller;
        private ServiceProcessInstaller processInstaller;
        public MonitorServiceInstaller()
        {

         
            Console.WriteLine("Read Service Information...");
            processInstaller = new ServiceProcessInstaller();
            serviceInstaller = new ServiceInstaller();
            processInstaller.Account = ServiceAccount.LocalSystem;

            serviceInstaller.StartType = ServiceStartMode.Automatic;
            serviceInstaller.ServiceName = s_serviceName;

            serviceInstaller.Description = s_serviceDesc;

            Installers.Add(serviceInstaller);
            Installers.Add(processInstaller);

            Console.WriteLine("End Read Service Information...");


        }

        public override void Commit(IDictionary savedState)
        {
            base.Commit(savedState);
            ServiceController sc = new ServiceController(s_serviceName);

            Console.WriteLine("Starting Service...");
            sc.Start();
        }
    }
}
